package com.nbsaas.boot;

import com.nbsaas.boot.lock.api.CountingLockService;
import com.nbsaas.boot.lock.impl.ReentrantLockCountingService;

public class LockServiceTest {
    public static void main(String[] args) {
        CountingLockService lockService = new ReentrantLockCountingService();

        System.out.println(lockService.lock("key1"));
        System.out.println(lockService.lock("key2"));
        System.out.println(lockService.lock("key1"));

        System.out.println("key1 Lock Count: " + lockService.getLockCount("key1")); // 输出: 1
        System.out.println("key2 Lock Count: " + lockService.getLockCount("key2")); // 输出: 1
        System.out.println("Total Lock Count: " + lockService.getTotalLockCount()); // 输出: 2
        System.out.println("Current Lock Count: " + lockService.getCurrentLockCount()); // 输出: 2

        lockService.unlock("key1");
        System.out.println("key1 Lock Count after unlock: " + lockService.getLockCount("key1")); // 输出: 0

        lockService.unlock("key1");
        System.out.println("Current Lock Count after all unlocks: " + lockService.getCurrentLockCount()); // 输出: 1
    }
}
